const fs = require('fs');


//注册全局中间件
function registerGloablMiddlewares(dir) {
    const prefix = `${__dirname}/${dir}`;
    //按文件创建时间排序
    const globalMiddlewarePaths = fs.readdirSync(prefix);
    globalMiddlewarePaths.forEach(path => {
        const middleware = require(`${prefix}/${path}`);
        this.use(middleware);
    })
}

function registerPreGloablMiddlewares() {
    this.registerGloablMiddlewares = registerGloablMiddlewares;
    this.registerGloablMiddlewares('preMiddlewares');
}

module.exports = {
    registerPreGloablMiddlewares
};